/**
 * 后台主界面主要JS方法和功能
 */

//--------------------------------------------------------------------------
//
//	框架调整
//
//--------------------------------------------------------------------------
// 右边框架区域最小宽度
var RightMinWidth = 650;

// 页面载入
$( "body" ).ready( function( e )
{
	resize_frame();
	resize_content();
	//$( "#frame_left_b" ).load( "admin_menu.php" );
} );

// 窗口大小改变
$( window ).resize( function( e )
{
	resize_frame();
	resize_content();
} );

function resize_content()
{
	var hh = $( "#frame_top" ).height();
	var bh = $( "body" ).height();

	$( "#frame_content" ).height( bh - hh );
}

// 重新调整框架模块的大小
function resize_frame()
{
	var bodyWidth = $( "body" ).width();
	var leftWidth = $( "#frame_left" ).width();
	var w = bodyWidth - leftWidth;

	w = w < RightMinWidth ? RightMinWidth : w;
	$( "#framer" ).width( w + leftWidth );
	$( "#frame_right" ).width( w );
}

//--------------------------------------------------------------------------
//
//	顶部菜单
//
//--------------------------------------------------------------------------

var oldLeftMenuWidth = 260;

function collapse_menu()
{
	var leftWidth = $( "#frame_left" ).width();
	var mode = $( "#frame_left" ).css( "display" ) == "none" ? "expand" : "collapse";

	if( mode == "expand" )
	{
		// speed: 毫秒
		// easing: swing, linear
		$( "#frame_left" ).animate( { width: oldLeftMenuWidth, opacity: 'show' }, 150, function()
		{
			collapse_menu_ex( "expand" );
		} );
	}
	else
	{
		oldLeftMenuWidth = leftWidth;
		$( "#frame_left" ).animate( { width: 0, opacity: 'hide' }, 150, function()
		{
			collapse_menu_ex( "collapse" );
		} );
	}

	// 以下 IE9 支持 div:resize 事件， Chrome 不支持
	$( "#frame_left" ).resize( function()
	{
		resize_frame();
	} );
}

function collapse_menu_ex( mode )
{
	if( mode == "expand" )
	{
		// 展开
		//$( "#frame_left" ).width( oldLeftMenuWidth );
		$( "#collapser" ).attr( "class", "btn_collapse" );
		$( "#collapser" ).attr( "title", "收起菜单列表" );
	}
	else
	{
		// 收起
		//$( "#frame_left" ).width( 0 );
		$( "#collapser" ).attr( "class", "btn_collapse_tor" );
		$( "#collapser" ).attr( "title", "展开菜单列表" );
	}

	resize_frame();
}

//--------------------------------------------------------------------------
//
//	左侧菜单
//
//--------------------------------------------------------------------------

function select_menu( title )
{
	var item = $( title ).parent().find( ".menu_items" );

	if( item.css( "display" ) == "none" )
	{
		item.show();
	}
	else
	{
		item.hide();
	}
}

function select_item( url )
{
	var e = window.event;

	if( e.ctrlKey )
	{
		var p = param( url );
		var id = url.split( "?" )[ 0 ];
		id = id.split( "." )[ 0 ];
		id += "_" + hash( 8 );

		if( url.indexOf( "consultant" ) == -1 )
		{
			infopad.err( "只支持对咨询师相关功能模块，进行多窗口多事务操作。" );
			return;
		}

		create_model( url, p.title, id );
		open_model( id );
	}
	else
	{
		$( "#content_container" ).attr( "src", url );
	}
}
